// 
// $Rev:: 21            $:  Revision of last commit
// $Author:: rvhaverm@g#$:  Author of last commit
// $Date:: 2010-07-25 1#$:  Date of last commit
// 
package agents.hosts;


import com.ibm.aglet.AgletContext;
import com.ibm.aglet.system.AgletRuntime;

import agents.aglets.AgletBridge;
import agents.configuration.IHostConfiguration;
import agents.core.Components;
import agents.interfaces.IAgentHost;
import agents.interfaces.IAgentHostFactory;
import agents.interfaces.ILogger;

public class AgentHostFactory implements IAgentHostFactory
{

    private AgletRuntime createRuntime(String user, String pass)
    {
	return AgletBridge.createRuntime(user, pass);
    }
    private AgletContext createContext(AgletRuntime runtime, String name)
    {
	return AgletBridge.createContext(runtime, name);
    }
    
    @Override
    public IAgentHost create(IHostConfiguration props)
    {
	AgletRuntime runtime = createRuntime(props.getRuntimeUser(), props.getRuntimePass());
	AgletContext context = createContext(runtime, props.getContextName());
	
	return new BaseAgentHost(props, runtime, context, Components.Instance().getLogger());
    }

    @Override
    public IAgentHost createHostBillBoardService(
	    IHostConfiguration props)
    {
	AgletRuntime runtime = createRuntime(props.getRuntimeUser(), props.getRuntimePass());
	AgletContext context = createContext(runtime, props.getContextName());
	ILogger logger = Components.Instance().getLogger();
	return new HostBillBoardService(props, runtime, context, logger);
    }
    
    @Override
    public IAgentHost createGraphicService(
	    IHostConfiguration props)
    {
	AgletRuntime runtime = createRuntime(props.getRuntimeUser(), props.getRuntimePass());
	AgletContext context = createContext(runtime, props.getContextName());
	ILogger logger = Components.Instance().getLogger();
	return new GraphicService(props, runtime, context, logger);
    }

}
